Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

focus-lock

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

focus-lock

DOM trap for a focus

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1M
decreased by-6.8%
Maintainers
1
Weekly downloads
 
Created

What is focus-lock?

The focus-lock npm package is designed to trap focus within a specified DOM element, typically used in modal dialogs, popups, and similar components to enhance accessibility and user experience. It prevents users from tabbing out of the focused area into other parts of the webpage, ensuring that keyboard and screen reader users have a confined, manageable interaction space.

What are focus-lock's main functionalities?

Focus trapping within a DOM element

This feature allows developers to create a focus trap around a specified DOM element. When activated, all tab and shift+tab keystrokes are confined within the element, enhancing accessibility for modal dialogs.

import { FocusTrap } from 'focus-lock';

const focusTrap = new FocusTrap('#myDialog');
focusTrap.activate();
// When done
focusTrap.deactivate();

Auto focusing on the first focusable element

Automatically focuses the first focusable element within the component when activated. This is useful for ensuring that users start interacting with the most relevant part of a newly opened UI component.

import { AutoFocusInside } from 'focus-lock';

<AutoFocusInside>
  <input type='text' />
  <button>Click me</button>
</AutoFocusInside>

Return focus to initial element on deactivation

When the focus lock is deactivated, focus can be programmatically moved back to the initially focused element before the focus lock was activated, maintaining a logical flow of interaction.

import { MoveFocusInside } from 'focus-lock';

const initialFocus = document.getElementById('initialFocus');
// After deactivating the focus lock
MoveFocusInside(initialFocus);

Other packages similar to focus-lock

Keywords

FAQs

Package last updated on 18 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc